home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / s / scrn2.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  7.7 KB  |  230 lines

  1.     TITLE scrn2.asm
  2.  
  3.  
  4.  
  5. ;    AUTHOR  Tim Spencer - Compuserve [73657,1400]
  6.  
  7. ;    DATE    March 15, 1987
  8.  
  9.  
  10.  
  11. _TEXT     SEGMENT BYTE PUBLIC 'CODE'
  12.  
  13. _TEXT    ENDS
  14.  
  15.  
  16.  
  17. _DATA     SEGMENT WORD PUBLIC 'DATA'
  18.  
  19.  
  20.  
  21. SCRN    STRUC        ; screen data structure - defined in video.h
  22.  
  23. off    dw    0    ; offset (cursor position) 
  24.  
  25. seg    dw    0    ; screen buffer address
  26.  
  27. port    dw    0    ; status port address
  28.  
  29. attrib    dw    0    ; attribute to use 
  30.  
  31. cgacrd    dw    0    ; retrace checking enabled if not zero
  32.  
  33. SCRN     ENDS
  34.  
  35.  
  36.  
  37. _DATA    ENDS
  38.  
  39.  
  40.  
  41. DGROUP    GROUP _DATA
  42.  
  43.     ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP, ES:NOTHING
  44.  
  45.  
  46.  
  47.  
  48.  
  49. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  50.  
  51.  
  52.  
  53. ;-----------------------------------------------------------------------;
  54.  
  55. ; scrn_puts - MSC callable routine for printing a string directly to     ;
  56.  
  57. ;          the screen buffer.                    ;
  58.  
  59. ;                                    ;
  60.  
  61. ; Usage:    scrn_puts(string, attribute, &structure_name);        ;
  62.  
  63. ;-----------------------------------------------------------------------;
  64.  
  65. _DATA    SEGMENT
  66.  
  67. scrn_puts_args STRUC        ; args as pushed by calling program
  68.  
  69.     dw    0        ; saved bp value
  70.  
  71.     dw    0        ; return address
  72.  
  73. str_ptr    dw    0        ; address of string
  74.  
  75. sstruc    dw    0        ; pointer to SCRN structure
  76.  
  77. scrn_puts_args ENDS
  78.  
  79. _DATA    ENDS
  80.  
  81.  
  82.  
  83.     PUBLIC _scrn_puts
  84.  
  85.  
  86.  
  87. _scrn_puts    PROC    NEAR
  88.  
  89.     push    bp            ;set up frame pointer
  90.  
  91.     mov    bp,sp        
  92.  
  93.     push    di
  94.  
  95.     push    si
  96.  
  97.     mov    si,[bp].str_ptr        ; get the string pointer 
  98.  
  99.         mov    bx,[bp].sstruc         ; get pointer to SCRN structure
  100.  
  101.     les    di,dword ptr[bx].off    ; put offset in di, buffer addr in es   
  102.  
  103.     mov    ch,byte ptr[bx].attrib    ; put attribute in cx
  104.  
  105.     mov    dx,[bx].port        ; get status port address
  106.  
  107.  
  108.  
  109. load_one:
  110.  
  111.     lodsb                ; load a char and advance str ptr
  112.  
  113.     or    al,al            ; is it null ?
  114.  
  115.     jz    puts_exit        ; yes, lovely chatting. Chow babe.
  116.  
  117.     mov    cl,al            ; no, save in cl for a few millisecs
  118.  
  119.     cmp    [bx].cgacrd, 0        ; cga card present?
  120.  
  121.     jnz    swait1            ; yes...go wait
  122.  
  123.     mov    ax,cx            ; no.
  124.  
  125.     stosw                ; write it
  126.  
  127.     jmp    short load_one        ; as fast as you can!
  128.  
  129. swait1:
  130.  
  131.         in      al, dx                  ; wait for end of retrace
  132.  
  133.         shr     al, 1                   ; test horizontal trace bit
  134.  
  135.         jc      swait1            ; loop if still tracing
  136.  
  137.         cli                             ; disable writus interuptus
  138.  
  139. swait2:
  140.  
  141.         in      al, dx                  ; now wait until the very moment
  142.  
  143.         shr     al, 1                   ; when the next retrace begins
  144.  
  145.         jnc     swait2            ; still waiting...
  146.  
  147.         mov     al,cl            ; load the char into al for stosb
  148.  
  149.         stosb                ; write it and update pointer
  150.  
  151.         sti                             ; enable interrupts again
  152.  
  153. swait3:
  154.  
  155.         in      al, dx                  ; repeat these steps for the attribute
  156.  
  157.         shr     al, 1
  158.  
  159.         jc      swait3
  160.  
  161.         cli                             
  162.  
  163. swait4:
  164.  
  165.         in      al, dx                  
  166.  
  167.         shr     al, 1                   
  168.  
  169.     jnc     swait4
  170.  
  171.         mov     al,ch            ; load the attribute
  172.  
  173.         stosb
  174.  
  175.         sti                             
  176.  
  177.     jmp    short load_one        ; and get another
  178.  
  179.  
  180.  
  181. puts_exit:
  182.  
  183.     mov    [bx].off,di         ; save new offset ( cur pos )
  184.  
  185.     pop    si
  186.  
  187.     pop    di
  188.  
  189.     pop    bp
  190.  
  191.     ret
  192.  
  193. _scrn_puts    ENDP
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. ;-----------------------------------------------------------------------;
  202.  
  203. ; scrn_putca - MSC callable function to print a char and attribute    ;
  204.  
  205. ;           directly to the screen buffer. The logical cursor    ;
  206.  
  207. ;           position IS UPDATED on return.                ;    
  208.  
  209. ;                                    ;
  210.  
  211. ; Usage:    scrn_putca(char, attribute, &structure_name        ;
  212.  
  213. ;-----------------------------------------------------------------------;
  214.  
  215. _DATA    SEGMENT
  216.  
  217. scrn_putca_args STRUC            ; args as pushed by calling program
  218.  
  219.     dw    0             ; saved bp value
  220.  
  221.     dw    0            ; return address
  222.  
  223. pchar    dw    0            ; char to write
  224.  
  225. pstruc    dw    0            ; pointer to SCRN structure
  226.  
  227. scrn_putca_args ENDS
  228.  
  229. _DATA    ENDS
  230.  
  231.  
  232.  
  233.     PUBLIC    _scrn_putca    
  234.  
  235.  
  236.  
  237. _scrn_putca    PROC    NEAR
  238.  
  239.     push    bp            ; set up frame pointer
  240.  
  241.     mov    bp,sp
  242.  
  243.     push    di
  244.  
  245.     mov    bx,[bp].pstruc        ; get pointer to SCRN structure
  246.  
  247.     les    di,dword ptr[bx].off    ; get offset in di, buffer addr in es
  248.  
  249.     mov    dx,[bx].port        ; status port address
  250.  
  251.     mov    ch,byte ptr[bx].attrib    ; get attribute into ch
  252.  
  253.     mov    cl,byte ptr[bp].pchar    ;  and char into cl
  254.  
  255.     cmp    [bx].cgacrd, 0        ; cga card present?
  256.  
  257.     jnz    cwait1            ; yes...go wait
  258.  
  259.     mov    ax,cx            ; no.
  260.  
  261.     stosw                ; write it
  262.  
  263.     jmp    short cexit        ; exit.
  264.  
  265.  
  266.  
  267. cwait1:
  268.  
  269.         in      al, dx                  ; wait for end of retrace
  270.  
  271.         shr     al, 1                   ; test horizontal trace bit
  272.  
  273.         jc      cwait1            ; loop if still tracing
  274.  
  275.         cli                             ; disable writus interuptus
  276.  
  277. cwait2:
  278.  
  279.         in      al, dx                  ; now wait until the very moment
  280.  
  281.         shr     al, 1                   ; when the next retrace begins
  282.  
  283.         jnc     cwait2            ; still waiting...
  284.  
  285.         mov     al,cl            ; load the char into al for stosb
  286.  
  287.         stosb                ; write it and update pointer
  288.  
  289.         sti                             ; enable interrupts again
  290.  
  291. cwait3:
  292.  
  293.         in      al, dx                  ; repeat these steps for the attribute
  294.  
  295.         shr     al, 1
  296.  
  297.         jc      cwait3
  298.  
  299.         cli                             
  300.  
  301. cwait4:
  302.  
  303.         in      al, dx                  
  304.  
  305.         shr     al, 1                   
  306.  
  307.     jnc     cwait4
  308.  
  309.         mov     al,ch            ; load the attribute
  310.  
  311.         stosb
  312.  
  313.         sti                ; whew...all done...enable interrupts
  314.  
  315. cexit:
  316.  
  317.     mov    [bx].off, di        ; update logical cursor position
  318.  
  319.     pop    di            ;  (offset) before leaving
  320.  
  321.     pop    bp
  322.  
  323.     ret    
  324.  
  325. _scrn_putca    ENDP
  326.  
  327.  
  328.  
  329.  
  330.  
  331. ;-----------------------------------------------------------------------;
  332.  
  333. ; _scrn_getca - get char and attrib from screen                ;
  334.  
  335. ;                                    ;
  336.  
  337. ; usage:    char = scrn_getca(&attrib,p_scn_data)             ;
  338.  
  339. ;                                    ;
  340.  
  341. ;-----------------------------------------------------------------------;
  342.  
  343. _DATA    SEGMENT
  344.  
  345. getca_args STRUC        ; input arguments
  346.  
  347.     dw    0        ; saved BP value
  348.  
  349.     dw    0        ; return address
  350.  
  351. gattrib    dw    0        ; store attribute here 
  352.  
  353. gstruct    dw    0        ; pointer to SCRN
  354.  
  355. getca_args ENDS
  356.  
  357. _DATA    ENDS
  358.  
  359.  
  360.  
  361.     PUBLIC    _scrn_getca
  362.  
  363.  
  364.  
  365. _scrn_getca    PROC    NEAR
  366.  
  367.     push    bp            ; set up frame pointer
  368.  
  369.     mov    bp,sp        
  370.  
  371.     push    si
  372.  
  373.     
  374.  
  375.         mov    bx,[bp].gstruct        ; get pointer to SCRN structure
  376.  
  377.     mov    dx,[bx].port        ; get status port address
  378.  
  379.     push    ds            ; lds uses ds - must save
  380.  
  381.     lds    si,dword ptr[bx].off    ; get offset and segment address
  382.  
  383. gwait1:
  384.  
  385.         in      al, dx                  ; wait for end of retrace
  386.  
  387.         shr     al, 1                   ; test horizontal trace bit
  388.  
  389.         jc      gwait1            ; loop if still tracing
  390.  
  391.         cli                             ; disable writus interuptus
  392.  
  393. gwait2:
  394.  
  395.         in      al, dx                  ; now wait until the very moment
  396.  
  397.         shr     al, 1                   ; when the next retrace begins
  398.  
  399.         jnc     gwait2            ; still waiting...
  400.  
  401.         lodsb                ; get the char into al
  402.  
  403.         sti                             ; enable interrupts again
  404.  
  405.     mov    cl,al            ; save the char in cl
  406.  
  407. gwait3:
  408.  
  409.         in      al, dx                  ; repeat these steps for the attribute
  410.  
  411.         shr     al, 1
  412.  
  413.         jc      gwait3
  414.  
  415.         cli                             
  416.  
  417. gwait4:
  418.  
  419.         in      al, dx                  
  420.  
  421.         shr     al, 1                   
  422.  
  423.     jnc     gwait4
  424.  
  425.         lodsb                ; get the attribute in al
  426.  
  427.         sti                             
  428.  
  429.     pop    ds            ; restore data segment to norm
  430.  
  431.     mov    word ptr [bx],si     ; update offset (logical cursor)
  432.  
  433.     mov    si,word ptr[bp].gattrib    ; get address to store attrib
  434.  
  435.         mov    byte ptr [si],al     ; store the attribute at "&attrib"
  436.  
  437.     mov    al,cl            ; move the char to al and
  438.  
  439.     xor    ah,ah            ;  zero out ah so that ax = char,
  440.  
  441.                     ;   the return value
  442.  
  443.     pop    si
  444.  
  445.     pop    bp
  446.  
  447.     ret
  448.  
  449. _scrn_getca    ENDP
  450.  
  451.         
  452.  
  453. _TEXT    ENDS
  454.  
  455.  
  456.  
  457.     END
  458.  
  459.